package Data_base;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
//删除
public class Shanchu {
    public void delete() throws Exception
    {
        try {
            DB ty = new DB();
            Class.forName(ty.Driver_class);
            Connection conn = DriverManager.getConnection(ty.Database_url, ty.Database_user, ty.Database_password);
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入要删除的id:");
            String zh = sc.nextLine();
            System.out.print("请输入密码:");
            String mm = sc.nextLine();
            Statement state = conn.createStatement();   //容器
            String sql = "delete from users where id='" + zh + "'";   //SQL语句
            state.executeUpdate(sql);         //将sql语句上传至数据库执行
            System.out.println("删除用户id为 " + zh + " 成功");
            conn.close();//关闭通道
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }

}
